/*
 * JsonUtil.java
 * This file contains Boeing intellectual property. It
 * may contain information about Boeing processes that are part of the Company's
 * competitive advantage. Release of this file requires prior approval from
 * Luxoft Management. Copyright (c) 2008, The Boeing Company All Rights Reserved
 */
package json;

import java.util.Map;

/**
 *
 * @author dakhoa
 * @version 1.0
 */
public class JsonUtil {

    public static String jsonProperty(String name, String value) {
        return new StringBuilder().append("\"").append(name).append("\"").
            append(":").append("\"").append(value).append("\"").append(",").toString();
    }

    public static String toJson(Map<String, Object> fieldValues) {
        StringBuilder sb = new StringBuilder("{");

        for (Map.Entry<String, Object> e : fieldValues.entrySet()) {
            if (e.getKey() != null && e.getValue() != null) {
                sb.append(jsonProperty(e.getKey(), e.getValue().toString()));
            }
        }

        sb.append("}");

        return sb.toString();
    }
}
